import random
from abc import ABC, abstractmethod

class BinaryOperation(ABC):
    """二元运算抽象基类"""
    def __init__(self, first_number, second_number):
        self.first_number = first_number
        self.second_number = second_number
    
    @abstractmethod
    def get_result(self):
        """获取运算结果"""
        pass
    
    @abstractmethod
    def get_operation_symbol(self):
        """获取运算符号"""
        pass
    
    def __str__(self):
        """返回算式字符串"""
        return f"{self.first_number} {self.get_operation_symbol()} {self.second_number} = "

class Addition(BinaryOperation):
    """加法类"""
    def get_result(self):
        return self.first_number + self.second_number
    
    def get_operation_symbol(self):
        return "+"
    
    @classmethod
    def generate_random(cls):
        """生成随机加法算式（和不超过100）"""
        num2 = random.randint(1, 99)
        num1 = random.randint(1, 100 - num2)
        return cls(num1, num2)

class Subtraction(BinaryOperation):
    """减法类"""
    def get_result(self):
        return self.first_number - self.second_number
    
    def get_operation_symbol(self):
        return "-"
    
    @classmethod
    def generate_random(cls):
        """生成随机减法算式（差不小于0）"""
        num1 = random.randint(1, 99)
        num2 = random.randint(0, num1)
        return cls(num1, num2) 